package org.jeecg.eqp.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.eqp.entity.EqpSpchkheadValue;
import org.jeecg.eqp.mapper.EqpSpchkdetailValueMapper;
import org.jeecg.eqp.mapper.EqpSpchkheadValueMapper;
import org.jeecg.eqp.service.IEqpSpchkheadValueService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.eqp.vo.EqpMaintainDetailVO;
import org.jeecg.eqp.vo.EqpMaintainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.*;

/**
 * @Description: 点检记录表
 * @Author: shaolong
 * @Date: 2022-10-13
 * @Version: V1.0
 */
@Service
public class EqpSpchkheadValueServiceImpl extends ServiceImpl<EqpSpchkheadValueMapper, EqpSpchkheadValue> implements IEqpSpchkheadValueService {

	@Autowired
	private EqpSpchkheadValueMapper eqpSpchkheadValueMapper;
	@Autowired
	private EqpSpchkdetailValueMapper eqpSpchkdetailValueMapper;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		eqpSpchkdetailValueMapper.deleteByMainId(id);
		//把这里的删除给改了 改成按照id删
		Map<String, Object> map = new HashMap<>();
		map.put("REC_ID", id);
		eqpSpchkheadValueMapper.deleteByMap(map);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for (Serializable id : idList) {
			eqpSpchkdetailValueMapper.deleteByMainId(id.toString());
			eqpSpchkheadValueMapper.deleteById(id);
		}
	}

	@Override
	public Result<String> edit(EqpSpchkheadValue eqpSpchkheadValue) {
		LambdaUpdateWrapper<EqpSpchkheadValue> eq = new LambdaUpdateWrapper<EqpSpchkheadValue>();
		eq.eq(EqpSpchkheadValue::getRecId, eqpSpchkheadValue.getRecId());
		boolean update = update(eqpSpchkheadValue, eq);
		return update ? Result.ok("修改成功!") : Result.error("修改失败!");
	}

	@Override
	public List<EqpMaintainVO> getMaintainList(EqpSpchkheadValue eqpSpchkheadValue) {
		return eqpSpchkheadValueMapper.getMaintainList(eqpSpchkheadValue);
	}

	@Override
	public List<EqpMaintainDetailVO> queryEqpDetailList(EqpSpchkheadValue eqpSpchkheadValue) {
		return eqpSpchkheadValueMapper.getEqpDetailList(eqpSpchkheadValue);
	}
}
